package uy.edu.um.ltic.server.communication;

import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.util.ArrayList;

import uy.edu.um.ltic.commons.ConferenceRemoteMgt;
import uy.edu.um.ltic.commons.ConferenceVO;
import uy.edu.um.ltic.commons.EmployeeVO;
import uy.edu.um.ltic.exception.DataBaseException;
import uy.edu.um.ltic.server.business.Conference;
import uy.edu.um.ltic.server.business.ConferenceFactory;
import uy.edu.um.ltic.server.business.ConferenceReminderStarter;
import uy.edu.um.ltic.server.business.Employee;

public class ConferenceRemoteServerMgr implements ConferenceRemoteMgt{

	private static ConferenceRemoteServerMgr instance = null;

	private ConferenceRemoteServerMgr() throws RemoteException{
				
	}

	public static ConferenceRemoteServerMgr getInstance()  throws RemoteException{
		if (instance == null) {
			instance = new ConferenceRemoteServerMgr();
		}
		return instance;
	}
	
	@Override
	public void addConference(ConferenceVO oConfVO) throws RemoteException, DataBaseException {
		ConferenceFactory.getInstance().getConferenceMgt().addConference(new Conference(oConfVO));
	}

	@Override
	public void deleteConference(ConferenceVO oConfVO) throws RemoteException, DataBaseException {
		ConferenceFactory.getInstance().getConferenceMgt().deleteConference(new Conference(oConfVO));
	}

	@Override
	public ArrayList<ConferenceVO> getConferencesImIn(EmployeeVO oEmployeeVO)
			throws RemoteException, DataBaseException {
		ArrayList<Conference> oListConf = ConferenceFactory.getInstance().getConferenceMgt().getConferencesImIn(new Employee(oEmployeeVO));
		ArrayList<ConferenceVO> oListConfVO = new ArrayList<ConferenceVO>();
		for(Conference conf : oListConf){
			oListConfVO.add(conf.convertToConferenceVO());
		}
		
		return oListConfVO;
	}

	@Override
	public ArrayList<ConferenceVO> getConferencesImTheOrganizer(
			EmployeeVO oEmployeeVO) throws RemoteException, DataBaseException {
		ArrayList<Conference> oListConf = ConferenceFactory.getInstance().getConferenceMgt().getConferencesImTheOrganizer(new Employee(oEmployeeVO));
		ArrayList<ConferenceVO> oListConfVO = new ArrayList<ConferenceVO>();
		for(Conference conf : oListConf){
			oListConfVO.add(conf.convertToConferenceVO());
		}
		
		return oListConfVO;
	}
	
	public ArrayList<EmployeeVO> getAllParticipants(int idConference) throws DataBaseException{
		ArrayList<EmployeeVO> oListEmpl = new ArrayList<EmployeeVO>();
		for (Employee oEmpl : ConferenceFactory.getInstance().getConferenceMgt().getAllParticipants(idConference)){
			oListEmpl.add(oEmpl.convertToEmployeeVO());
		}
		return oListEmpl;
	}

	@Override
	public String getConferenceName(int idConf) throws RemoteException, DataBaseException {
		return ConferenceFactory.getInstance().getConferenceMgt().getConferenceName(idConf);
				
	}
	
}
